package com.ideaaedi.commonspring.lite.ratelimiter;

/**
 * 限流异常
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img
 * src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2100.10.17.LTS17
 */
public class RateLimitException extends RuntimeException {

    /**
     * 限流注解信息 key
     */
    private final RateLimiter rateLimiter;

    /**
     * spel解析后的限流器唯一标识
     */
    private final String finalUid;

    public RateLimitException(String finalUid, RateLimiter rateLimiter) {
        super(String.format("finalUid=%s,uid=%s, tokenLimit=%d, interval=%s, intervalUnit=%s, condition=%s, additionalInfo=%s",
                finalUid, rateLimiter.uid(), rateLimiter.tokenLimit(), rateLimiter.interval(),
                rateLimiter.intervalUnit(), rateLimiter.condition(), rateLimiter.additionalInfo()));
        this.finalUid = finalUid;
        this.rateLimiter = rateLimiter;
    }

    public RateLimiter getRateLimiter() {
        return rateLimiter;
    }

    public String getFinalUid() {
        return finalUid;
    }
}
